package com.example.tb_base.base_viewmodel_activity_fragment

import android.os.Bundle
import android.view.View
import androidx.viewbinding.ViewBinding
import com.example.tb_base.BaseRepository
import com.example.tb_base.BaseViewModel
import com.example.tb_base.base_viewbinding_activity_fragment.BaseViewBindingFragment

/**
 * 基于ViewBinding和ViewModel的Fragment基类，统一处理布局加载、WindowInsets适配等通用逻辑。
 * 子类只需实现抽象方法即可快速搭建自己的Fragment。
 */
abstract class BaseViewModelFragment<V : ViewBinding, VM : BaseViewModel<BaseRepository>, SVM : BaseViewModel<BaseRepository>> :
    BaseViewBindingFragment<V>() {

    protected val viewModel: VM by lazy {
        createViewModel()
    }

    protected val shareViewModel: SVM? by lazy { createShareViewModel() }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initObservers()
    }

    protected abstract fun createViewModel(): VM
    protected abstract fun createShareViewModel(): SVM?
    protected abstract fun initObservers()
}